import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'

Vue.use(VueRouter)

const routes = [
  {
    path:'/',
    redirect:'/home/index'
  },
  {
    path:'/login',
    name:'login',
    component:()=>import('../views/Login.vue')
  },
  {
    path: '/home',
    name: 'home',
    component: HomeView,
    children:[
      {
        path:'index',
        name:'/home/index',
        component:()=>import('../views/Index.vue')
      },
      {
        path:'branch-list',
        name:'/home/branch-list',
        component:()=>import('../views/branch/BranchList.vue')
      },
      {
        path:'branch-add',
        name:'/home/branch-add',
        component:()=>import('../views/branch/BranchAdd.vue')
      },
      {
        path:'dept-list',
        name:'/home/dept-list',
        component:()=>import('../views/dept/DeptList.vue')
      },
      {
        path:'dept-add',
        name:'/home/dept-add',
        component:()=>import('../views/dept/DeptAdd.vue')
      },
      {
        path:'emp-list',
        name:'/home/emp-list',
        component:()=>import('../views/emp/EmpList.vue')
      },
      {
        path:'emp-add',
        name:'/home/emp-add',
        component:()=>import('../views/emp/EmpAdd.vue')
      },
      {
        path:'type-list',
        name:'/home/type-list',
        component:()=>import('../views/type/TypeList.vue')
      },
      {
        path:'type-add',
        name:'/home/typt-add',
        component:()=>import('../views/type/TypeAdd.vue')
      },
      {
        path:'shanghai-list',
        name:'/home/shanghai-list',
        component:()=>import('../views/shanghai/ShanghaiList.vue')
      },
      {
        path:'shanghai-add',
        name:'/home/shanghai-add',
        component:()=>import('../views/shanghai/ShanghaiAdd.vue')
      },
      {
        path:'beijing-list',
        name:'/home/beijing-list',
        component:()=>import('../views/beijing/BeijingList.vue')
      },
      {
        path:'beijing-add',
        name:'/home/beijing-add',
        component:()=>import('../views/beijing/BeijingAdd.vue')
      },
      {
        path:'shenzhen-list',
        name:'/home/shenzhen-list',
        component:()=>import('../views/shenzhen/ShenzhenList.vue')
      },
      {
        path:'shenzhen-add',
        name:'/home/shenzhen-add',
        component:()=>import('../views/shenzhen/ShenzhenAdd.vue')
      },
      {
        path:'guangzhou-list',
        name:'/home/guangzhou-list',
        component:()=>import('../views/guangzhou/GuangzhouList.vue')
      },
      {
        path:'guangzhou-add',
        name:'/home/guangzhou-add',
        component:()=>import('../views/guangzhou/GuangzhouAdd.vue')
      },
      {
        path:'chongqing-list',
        name:'/home/chongqing-list',
        component:()=>import('../views/chongqing/ChongqingList.vue')
      },
      {
        path:'chongqing-add',
        name:'/home/chongqing-add',
        component:()=>import('../views/chongqing/ChongqingAdd.vue')
      },
      {
        path:'hangzhou-list',
        name:'/home/hangzhou-list',
        component:()=>import('../views/hangzhou/HangzhouList.vue')
      },
      {
        path:'hangzhou-add',
        name:'/home/hangzhou-add',
        component:()=>import('../views/hangzhou/HangzhouAdd.vue')
      },
      {
        path:'chengdu-list',
        name:'/home/chengdu-list',
        component:()=>import('../views/chengdu/ChengduList.vue')
      },
      {
        path:'chengdu-add',
        name:'/home/chengdu-add',
        component:()=>import('../views/chengdu/ChengduAdd.vue')
      },
      {
        path:'nanjing-list',
        name:'/home/nanjing-list',
        component:()=>import('../views/nanjing/NanjingList.vue')
      },
      {
        path:'nanjing-add',
        name:'/home/nanjing-add',
        component:()=>import('../views/nanjing/NanjingAdd.vue')
      },
      {
        path:'wuhan-list',
        name:'/home/wuhan-list',
        component:()=>import('../views/wuhan/WuhanList.vue')
      },
      {
        path:'wuhan-add',
        name:'/home/wuhan-add',
        component:()=>import('../views/wuhan/WuhanAdd.vue')
      },
      {
        path:'suzhou-list',
        name:'/home/suzhou-list',
        component:()=>import('../views/suzhou/SuzhouList.vue')
      },
      {
        path:'suzhou-add',
        name:'/home/suzhou-add',
        component:()=>import('../views/suzhou/SuzhouAdd.vue')
      },
      
      
    ],
  },
  
  
  
  
]

const router = new VueRouter({
  routes
})

//全局前置守卫
router.beforeEach((to,from,next)=>{
  if(to.path=='/login'){
    return next()
  }else{
    if(sessionStorage.getItem('user')){
      return next()
    }else{
      router.push('/login')
    }
    
  }
})

export default router
